<?php

namespace app\admin\controller;

use app\common\controller\AdminController;

//引入外部函数
use app\common\model\hfztcy\LibWithdrawalAccounts;
use common\Common;


/**
 * 提现账号管理
 * @name WithdrawalAccounts.php
 * @package hfztcy
 * @category controller
 * @author rxy
 * @version 1.0
 * @copyright CHANGE INC
 * @since 2020-6-5
 */
class WithdrawalAccounts extends AdminController
{
    protected $model;

    /**
     * 构造函数
     */
    public function __construct()
    {
        $this->model = new LibWithdrawalAccounts();
        $this->rightVerify(session('admin'), url("admin/Login/login"));
        parent::__construct();
    }

    /**
     * 普通会员-列表页
     */
    function withdrawalAccountsList()
    {
        $this->getSetMenu($this);
        $this->assign('state',0);
        $this->log(__CLASS__, __FUNCTION__, "游客-列表页", 1, 'view');
        return $this->fetch('WithdrawalAccounts/withdrawalAccounts/withdrawalAccounts');
    }

    /**
     * 普通会员-列表页
     */
    function withdrawalAccounts1List()
    {
        $this->getSetMenu($this);
        $this->assign('state',1);
        $this->log(__CLASS__, __FUNCTION__, "普通会员-列表页", 1, 'view');
        return $this->fetch('WithdrawalAccounts/withdrawalAccounts/withdrawalAccounts');
    }

    /**
     * vip会员-列表页
     */
    function withdrawalAccounts2List()
    {
        $this->getSetMenu($this);
        $this->assign('state',2);
        $this->log(__CLASS__, __FUNCTION__, "vip会员-列表页", 1, 'view');
        return $this->fetch('WithdrawalAccounts/withdrawalAccounts/withdrawalAccounts');
    }

    /**
     * vip会员-列表页
     */
    function withdrawalAccounts3List()
    {
        $this->getSetMenu($this);
        $this->assign('state',5);
        $this->log(__CLASS__, __FUNCTION__, "vip会员-列表页", 1, 'view');
        return $this->fetch('WithdrawalAccounts/withdrawalAccounts/withdrawalAccounts');
    }

    /**
     * 红娘-列表页
     */
    function withdrawalAccounts4List()
    {
        $this->getSetMenu($this);
        $this->assign('state',3);
        $this->log(__CLASS__, __FUNCTION__, "红娘-列表页", 1, 'view');
        return $this->fetch('WithdrawalAccounts/withdrawalAccounts/withdrawalAccounts');
    }

    /**
     * 门店-列表页
     */
    function withdrawalAccounts5List()
    {
        $this->getSetMenu($this);
        $this->assign('state',4);
        $this->log(__CLASS__, __FUNCTION__, "门店-列表页", 1, 'view');
        return $this->fetch('WithdrawalAccounts/withdrawalAccounts/withdrawalAccounts');
    }

    /**
     * 分页查询
     */
    function pagingWithdrawalAccount()
    {
        $args = $this->getArgsList($this, ['user_id', 'username', 'type','state']);
        $page = $this->getPageInfo();
        $where = [];
        if (!empty($args['state'])) {
            if ($args['state'] != 5) {
                $where[] = "FIND_IN_SET({$args['state']},identity)";
            } else {
                $where[] = "(`a`.`is_vip_video` > 0 or `a`.`is_red_mother_video` > 0)";
            }
        }
        if (!empty($args['user_id'])) $where[] = "`user_id` = " . $args['user_id'];
        if (!empty($args['username'])) $where[] = "`memberUsername` = '" . $args['username'] . "'";
        if (!empty($args['type'])) $where[] = "`type` = " . $args['type'];

        $result = $this->model->pagingWithdrawalAccount($page, implode(' AND ', $where));
        echo json_encode($result);
    }

    /**
     * Info: 审核同意
     * Date: 2022/6/20 11:24
     */
    public function changeStatusOrder()
    {
        $id = input("id");
        $status = input("state");

        $result = $this->model->findWithdrawalAccount(['id' => $id]);
        if ($result['errorCode'] == 1) {
            echo json_encode(Common::errorArray(1, '错误', ''));
            die();
        }
        if ($result['data']['audit_status'] > 0) {
            echo json_encode(Common::errorArray(1, '已审核', ''));
            die();
        }
        if ($status == 1) {
            $reason = '审核成功';
        } else {
            $reason = input("reason");
        }
        $data['audit_status'] = $status;
        $data['audit_msg'] = $reason;
        $data['audit_user_id'] = session('admin.id');
        $data['audit_time'] = Common::getTime();
        $this->model->updateWithdrawalAccount(['id' => $id], $data);

        echo json_encode($result);
    }
}

?>